

//William Keller (#996964933) Section 1

#include <string.h>
#include <ctype.h>
#include <stdio.h>

int is_palindrome(char *str) {
	int len = strlen(str);
	int i, f = 1;
	for(i = 0; i < len; i++) {
		f = (str[i] != str[len-i-1]) ? 0 : f; // compare without the null terminator
	}
	return f;
}

int is_valid(char *str) { // it would make more sense to call normalize first and only check for uppers, but the program spec asks for comparison against lowers.
	int i, len = strlen(str);
	for(i = 0; i < len; i++) {
		if (strchr("atcgATCG", str[i]) == 0) {
            return 0;
        }
	}
	return 1;
}

char sub(char in) {
    switch (in) {
        case 'A':
            return 'T';
            break;

        case 'T':
            return 'A';
            break;

        case 'C':
            return 'G';
            break;

        case 'G':
            return 'C';
            break;
    }
    return 'E'; // for error, to keep gcc happy.
}

void normalize(char *str) {
	int i, len = strlen(str);
	for(i = 0; i<len; i++) {
	    str[i] = toupper(str[i]);
	}
}

void rev_comp(char *str) {
    int i, j = strlen(str) - 1;
    char tmp;
    
    for(i = 0; i <= j; i++, j--) { // reverse and swap with other base
        tmp = str[i];
        str[i] = sub(str[j]);
        str[j] = sub(tmp);
    }
}

